home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / demos / morph3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  40.1 KB  |  874 lines

  1. /*-
  2.  * morph3d.c - Shows 3D morphing objects (TK Version)
  3.  *
  4.  * This program was inspired on a WindowsNT(R)'s screen saver. It was written 
  5.  * from scratch and it was not based on any other source code. 
  6.  * 
  7.  * Porting it to xlock (the final objective of this code since the moment I
  8.  * decided to create it) was possible by comparing the original Mesa's gear
  9.  * demo with it's ported version, so thanks for Danny Sung for his indirect
  10.  * help (look at gear.c in xlock source tree). NOTE: At the moment this code
  11.  * was sent to Brian Paul for package inclusion, the XLock Version was not
  12.  * available. In fact, I'll wait it to appear on the next Mesa release (If you
  13.  * are reading this, it means THIS release) to send it for xlock package 
  14.  * inclusion). It will probably there be a GLUT version too.
  15.  *
  16.  * Thanks goes also to Brian Paul for making it possible and inexpensive
  17.  * to use OpenGL at home.
  18.  *
  19.  * Since I'm not a native english speaker, my apologies for any gramatical
  20.  * mistake.
  21.  *
  22.  * My e-mail addresses are
  23.  *
  24.  * vianna@cat.cbpf.br 
  25.  *         and
  26.  * marcelo@venus.rdc.puc-rio.br
  27.  *
  28.  * Marcelo F. Vianna (Feb-13-1997)
  29.  */
  30.  
  31. /*
  32. This document is VERY incomplete, but tries to describe the mathematics used
  33. in the program. At this moment it just describes how the polyhedra are 
  34. generated. On futhurer versions, this document will be probabbly improved.
  35.  
  36. Since I'm not a native english speaker, my apologies for any gramatical
  37. mistake.
  38.  
  39. Marcelo Fernandes Vianna 
  40. - Undergraduate in Computer Engeneering at Catholic Pontifical University
  41. - of Rio de Janeiro (PUC-Rio) Brasil.
  42. - e-mail: vianna@cat.cbpf.br or marcelo@venus.rdc.puc-rio.br
  43. - Feb-13-1997
  44.  
  45. POLYHEDRA GENERATION
  46.  
  47. For the purpose of this program it's not sufficient to know the polyhedra
  48. vertexes coordinates. Since the morphing algorithm applies a nonlinear 
  49. transformation over the surfaces (faces) of the polyhedron, each face has
  50. to be divided into smaller ones. The morphing algorithm needs to transform 
  51. each vertex of these smaller faces individually. It's a very time consoming
  52. task.
  53.  
  54. In order to reduce calculation overload, and since all the macro faces of
  55. the polyhedron are transformed by the same way, the generation is made by 
  56. creating only one face of the polyhedron, morphing it and then rotating it
  57. around the polyhedron center. 
  58.  
  59. What we need to know is the face radius of the polyhedron (the radius of 
  60. the inscribed sphere) and the angle between the center of two adjacent 
  61. faces using the center of the sphere as the angle's vertex.
  62.  
  63. The face radius of the regular polyhedra are known values which I decided
  64. to not waste my time calculating. Following is a table of face radius for
  65. the regular polyhedra with edge length = 1:
  66.  
  67.     TETRAHEDRON  : 1/(2*sqrt(2))/sqrt(3)
  68.     CUBE     : 1/2
  69.     OCTAHEDRON   : 1/sqrt(6)
  70.     DODECAHEDRON : T^2 * sqrt((T+2)/5) / 2     -> where T=(sqrt(5)+1)/2
  71.     ICOSAHEDRON  : (3*sqrt(3)+sqrt(15))/12
  72.  
  73. I've not found any reference about the mentioned angles, so I needed to
  74. calculate them, not a trivial task until I figured out how :)
  75. Curiously these angles are the same for the tetrahedron and octahedron.
  76. A way to obtain this value is inscribing the tetrahedron inside the cube
  77. by matching their vertexes. So you'll notice that the remaining unmatched
  78. vertexes are in the same straight line starting in the cube/tetrahedron
  79. center and crossing the center of each tetrahedron's face. At this point
  80. it's easy to obtain the bigger angle of the isosceles triangle formed by
  81. the center of the cube and two opposite vertexes on the same cube face.
  82. The edges of this triangle have the following lenghts: sqrt(2) for the base
  83. and sqrt(3)/2 for the other two other edges. So the angle we want is:
  84.      +-----------------------------------------------------------+
  85.      | 2*ARCSIN(sqrt(2)/sqrt(3)) = 109.47122063449069174 degrees |
  86.      +-----------------------------------------------------------+
  87. For the cube this angle is obvious, but just for formality it can be
  88. easily obtained because we also know it's isosceles edge lenghts:
  89. sqrt(2)/2 for the base and 1/2 for the other two edges. So the angle we 
  90. want is:
  91.      +-----------------------------------------------------------+
  92.      | 2*ARCSIN((sqrt(2)/2)/1)   = 90.000000000000000000 degrees |
  93.      +-----------------------------------------------------------+
  94. For the octahedron we use the same idea used for the tetrahedron, but now
  95. we inscribe the cube inside the octahedron so that all cubes's vertexes
  96. matches excatly the center of each octahedron's face. It's now clear that
  97. this angle is the same of the thetrahedron one:
  98.      +-----------------------------------------------------------+
  99.      | 2*ARCSIN(sqrt(2)/sqrt(3)) = 109.47122063449069174 degrees |
  100.      +-----------------------------------------------------------+
  101. For the dodecahedron it's a little bit harder because it's only relationship
  102. with the cube is useless to us. So we need to solve the problem by another
  103. way. The concept of Face radius also exists on 2D polygons with the name
  104. Edge radius:
  105.   Edge Radius For Pentagon (ERp)
  106.   ERp = (1/2)/TAN(36 degrees) * VRp = 0.6881909602355867905
  107.   (VRp is the pentagon's vertex radio).
  108.   Face Radius For Dodecahedron
  109.   FRd = T^2 * sqrt((T+2)/5) / 2 = 1.1135163644116068404
  110. Why we need ERp? Well, ERp and FRd segments forms a 90 degrees angle, 
  111. completing this triangle, the lesser angle is a half of the angle we are 
  112. looking for, so this angle is:
  113.      +-----------------------------------------------------------+
  114.      | 2*ARCTAN(ERp/FRd)     = 63.434948822922009981 degrees |
  115.      +-----------------------------------------------------------+
  116. For the icosahedron we can use the same method used for dodecahedron (well
  117. the method used for dodecahedron may be used for all regular polyhedra)
  118.   Edge Radius For Triangle (this one is well known: 1/3 of the triangle height)
  119.   ERt = sin(60)/3 = sqrt(3)/6 = 0.2886751345948128655
  120.   Face Radius For Icosahedron
  121.   FRi= (3*sqrt(3)+sqrt(15))/12 = 0.7557613140761707538
  122. So the angle is:
  123.      +-----------------------------------------------------------+
  124.      | 2*ARCTAN(ERt/FRi)     = 41.810314895778596167 degrees |
  125.      +-----------------------------------------------------------+
  126.  
  127. */
  128.  
  129.  
  130. #include <stdio.h>
  131. #include <stdlib.h>
  132. #include <unistd.h>
  133. #include <gltk.h>
  134. #include <math.h>
  135. #include <string.h>
  136.  
  137. #define Scale                      0.3
  138.  
  139. #define VectMul(X1,Y1,Z1,X2,Y2,Z2) (Y1)*(Z2)-(Z1)*(Y2),(Z1)*(X2)-(X1)*(Z2),(X1)*(Y2)-(Y1)*(X2)
  140. #define sqr(A)                     ((A)*(A))
  141.  
  142. /* Increasing this values produces better image quality, the price is speed. */
  143. /* Very low values produces erroneous/incorrect plotting */
  144. #define tetradivisions             23
  145. #define cubedivisions              20
  146. #define octadivisions              21
  147. #define dodecadivisions            10
  148. #define icodivisions               15
  149.  
  150. #define tetraangle                 109.47122063449069174
  151. #define cubeangle                  90.000000000000000000
  152. #define octaangle                  109.47122063449069174
  153. #define dodecaangle                63.434948822922009981
  154. #define icoangle                   41.810314895778596167
  155.  
  156. #ifndef Pi
  157. #define Pi                         3.1415926535897932385
  158. #endif
  159. #define SQRT2                      1.4142135623730951455
  160. #define SQRT3                      1.7320508075688771932
  161. #define SQRT5                      2.2360679774997898051
  162. #define SQRT6                      2.4494897427831778813
  163. #define SQRT15                     3.8729833462074170214
  164. #define cossec36_2                 0.8506508083520399322
  165. #define cos72                      0.3090169943749474241
  166. #define sin72                      0.9510565162951535721
  167. #define cos36                      0.8090169943749474241
  168. #define sin36                      0.5877852522924731292
  169.  
  170. /*************************************************************************/
  171.  
  172. static int       mono=0;
  173. static int       smooth=1;
  174. static GLint     WindH, WindW;
  175. static GLfloat   step=0;
  176. static GLfloat   seno;
  177. static int       object;
  178. static int       edgedivisions;
  179. static void      (*draw_object)( void );
  180. static float     Magnitude;
  181. static float     *MaterialColor[20];
  182.  
  183. static float front_shininess[] =   {60.0};
  184. static float front_specular[]  =   { 0.7, 0.7, 0.7, 1.0 };
  185. static float ambient[]         =   { 0.0, 0.0, 0.0, 1.0 };
  186. static float diffuse[]         =   { 1.0, 1.0, 1.0, 1.0 };
  187. static float position0[]       =   { 1.0, 1.0, 1.0, 0.0 };
  188. static float position1[]       =   {-1.0,-1.0, 1.0, 0.0 };
  189. static float lmodel_ambient[]  =   { 0.5, 0.5, 0.5, 1.0 };
  190. static float lmodel_twoside[]  =   {GL_TRUE};
  191.  
  192. static float MaterialRed[]     =   { 0.7, 0.0, 0.0, 1.0 };
  193. static float MaterialGreen[]   =   { 0.1, 0.5, 0.2, 1.0 };
  194. static float MaterialBlue[]    =   { 0.0, 0.0, 0.7, 1.0 };
  195. static float MaterialCyan[]    =   { 0.2, 0.5, 0.7, 1.0 };
  196. static float MaterialYellow[]  =   { 0.7, 0.7, 0.0, 1.0 };
  197. static float MaterialMagenta[] =   { 0.6, 0.2, 0.5, 1.0 };
  198. static float MaterialWhite[]   =   { 0.7, 0.7, 0.7, 1.0 };
  199. static float MaterialGray[]    =   { 0.2, 0.2, 0.2, 1.0 };
  200.  
  201. #define TRIANGLE(Edge, Amp, Divisions, Z)                                                                        \
  202. {                                                                                                                \
  203.   GLfloat   Xf,Yf,Xa,Yb,Xf2,Yf2;                                                                                 \
  204.   GLfloat   Factor,Factor1,Factor2;                                                                              \
  205.   GLfloat   VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ;                                               \
  206.   GLfloat   Ax,Ay,Bx;                                                                                            \
  207.   int       Ri,Ti;                                                                                               \
  208.   GLfloat   Vr=(Edge)*SQRT3/3;                                                                                   \
  209.   GLfloat   AmpVr2=(Amp)/sqr(Vr);                                                                                \
  210.   GLfloat   Zf=(Edge)*(Z);                                                                                       \
  211.                                                                                                                  \
  212.   Ax=(Edge)*(+0.5/(Divisions)), Ay=(Edge)*(-SQRT3/(2*Divisions));                                                \
  213.   Bx=(Edge)*(-0.5/(Divisions));                                                                                  \
  214.                                                                                                                  \
  215.   for (Ri=1; Ri<=(Divisions); Ri++) {                                                                            \
  216.     glBegin(GL_TRIANGLE_STRIP);                                                                                  \
  217.     for (Ti=0; Ti<Ri; Ti++) {                                                                                    \
  218.       Xf=(float)(Ri-Ti)*Ax + (float)Ti*Bx;                                                                       \
  219.       Yf=Vr+(float)(Ri-Ti)*Ay + (float)Ti*Ay;                                                                    \
  220.       Xa=Xf+0.001; Yb=Yf+0.001;                                                                                  \
  221.       Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);                                                           \
  222.       Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);                                                                          \
  223.       Factor2=1-((Xf2+sqr(Yb))*AmpVr2);                                                                          \
  224.       VertX=Factor*Xf;        VertY=Factor*Yf;        VertZ=Factor*Zf;                                           \
  225.       NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ;                                    \
  226.       NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ;                                    \
  227.       glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ));                                             \
  228.       glVertex3f(VertX, VertY, VertZ);                                                                           \
  229.                                                                                                                  \
  230.       Xf=(float)(Ri-Ti-1)*Ax + (float)Ti*Bx;                                                                     \
  231.       Yf=Vr+(float)(Ri-Ti-1)*Ay + (float)Ti*Ay;                                                                  \
  232.       Xa=Xf+0.001; Yb=Yf+0.001;                                                                                  \
  233.       Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);                                                           \
  234.       Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);                                                                          \
  235.       Factor2=1-((Xf2+sqr(Yb))*AmpVr2);                                                                          \
  236.       VertX=Factor*Xf;        VertY=Factor*Yf;        VertZ=Factor*Zf;                                           \
  237.       NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ;                                    \
  238.       NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ;                                    \
  239.       glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ));                                             \
  240.       glVertex3f(VertX, VertY, VertZ);                                                                           \
  241.                                                                                                                  \
  242.     }                                                                                                            \
  243.     Xf=(float)Ri*Bx;                                                                                             \
  244.     Yf=Vr+(float)Ri*Ay;                                                                                          \
  245.     Xa=Xf+0.001; Yb=Yf+0.001;                                                                                    \
  246.     Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);                                                             \
  247.     Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);                                                                            \
  248.     Factor2=1-((Xf2+sqr(Yb))*AmpVr2);                                                                            \
  249.     VertX=Factor*Xf;        VertY=Factor*Yf;        VertZ=Factor*Zf;                                             \
  250.     NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ;                                      \
  251.     NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ;                                      \
  252.     glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ));                                               \
  253.     glVertex3f(VertX, VertY, VertZ);                                                                             \
  254.     glEnd();                                                                                                     \
  255.   }                                                                                                              \
  256. }
  257.  
  258. #define SQUARE(Edge, Amp, Divisions, Z)                                                                          \
  259. {                                                                                                                \
  260.   int       Xi,Yi;                                                                                               \
  261.   GLfloat   Xf,Yf,Y,Xf2,Yf2,Y2,Xa,Yb;                                                                            \
  262.   GLfloat   Factor,Factor1,Factor2;                                                                              \
  263.   GLfloat   VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ;                                               \
  264.   GLfloat   Zf=(Edge)*(Z);                                                                                       \
  265.   GLfloat   AmpVr2=(Amp)/sqr((Edge)*SQRT2/2);                                                                    \
  266.                                                                                                                  \
  267.   for (Yi=0; Yi<(Divisions); Yi++) {                                                                             \
  268.     Yf=-((Edge)/2.0) + ((float)Yi)/(Divisions)*(Edge);                                                           \
  269.     Yf2=sqr(Yf);                                                                                                 \
  270.     Y=Yf+1.0/(Divisions)*(Edge);                                                                                 \
  271.     Y2=sqr(Y);                                                                                                   \
  272.     glBegin(GL_QUAD_STRIP);                                                                                      \
  273.     for (Xi=0; Xi<=(Divisions); Xi++) {                                                                          \
  274.       Xf=-((Edge)/2.0) + ((float)Xi)/(Divisions)*(Edge);                                                         \
  275.       Xf2=sqr(Xf);                                                                                               \
  276.                                                                                                                  \
  277.       Xa=Xf+0.001; Yb=Y+0.001;                                                                                   \
  278.       Factor=1-((Xf2+Y2)*AmpVr2);                                                                                \
  279.       Factor1=1-((sqr(Xa)+Y2)*AmpVr2);                                                                           \
  280.       Factor2=1-((Xf2+sqr(Yb))*AmpVr2);                                                                          \
  281.       VertX=Factor*Xf;        VertY=Factor*Y;         VertZ=Factor*Zf;                                           \
  282.       NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Y-VertY;  NeiAZ=Factor1*Zf-VertZ;                                    \
  283.       NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ;                                    \
  284.       glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ));                                             \
  285.       glVertex3f(VertX, VertY, VertZ);                                                                           \
  286.                                                                                                                  \
  287.       Xa=Xf+0.001; Yb=Yf+0.001;                                                                                  \
  288.       Factor=1-((Xf2+Yf2)*AmpVr2);                                                                               \
  289.       Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);                                                                          \
  290.       Factor2=1-((Xf2+sqr(Yb))*AmpVr2);                                                                          \
  291.       VertX=Factor*Xf;        VertY=Factor*Yf;        VertZ=Factor*Zf;                                           \
  292.       NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ;                                    \
  293.       NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ;                                    \
  294.       glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ));                                             \
  295.       glVertex3f(VertX, VertY, VertZ);                                                                           \
  296.     }                                                                                                            \
  297.     glEnd();                                                                                                     \
  298.   }                                                                                                              \
  299. }
  300.  
  301. #define PENTAGON(Edge, Amp, Divisions, Z)                                                                        \
  302. {                                                                                                                \
  303.   int       Ri,Ti,Fi;                                                                                            \
  304.   GLfloat   Xf,Yf,Xa,Yb,Xf2,Yf2;                                                                                 \
  305.   GLfloat   x[6],y[6];                                                                                           \
  306.   GLfloat   Factor,Factor1,Factor2;                                                                              \
  307.   GLfloat   VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ;                                               \
  308.   GLfloat   Zf=(Edge)*(Z);                                                                                       \
  309.   GLfloat   AmpVr2=(Amp)/sqr((Edge)*cossec36_2);                                                                 \
  310.                                                                                                                  \
  311.   for(Fi=0;Fi<6;Fi++) {                                                                                          \
  312.     x[Fi]=-cos( Fi*2*Pi/5 + Pi/10 )/(Divisions)*cossec36_2*(Edge);                                                \
  313.     y[Fi]=sin( Fi*2*Pi/5 + Pi/10 )/(Divisions)*cossec36_2*(Edge);                                                \
  314.   }                                                                                                              \
  315.                                                                                                                  \
  316.   for (Ri=1; Ri<=(Divisions); Ri++) {                                                                            \
  317.     for (Fi=0; Fi<5; Fi++) {                                                                                     \
  318.       glBegin(GL_TRIANGLE_STRIP);                                                                                \
  319.       for (Ti=0; Ti<Ri; Ti++) {                                                                                  \
  320.         Xf=(float)(Ri-Ti)*x[Fi] + (float)Ti*x[Fi+1];                                                             \
  321.         Yf=(float)(Ri-Ti)*y[Fi] + (float)Ti*y[Fi+1];                                                             \
  322.         Xa=Xf+0.001; Yb=Yf+0.001;                                                                                \
  323.     Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);                                                         \
  324.     Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);                                                                        \
  325.     Factor2=1-((Xf2+sqr(Yb))*AmpVr2);                                                                        \
  326.         VertX=Factor*Xf;        VertY=Factor*Yf;        VertZ=Factor*Zf;                                         \
  327.         NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ;                                  \
  328.         NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ;                                  \
  329.         glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ));                                           \
  330.     glVertex3f(VertX, VertY, VertZ);                                                                         \
  331.                                                                                                                  \
  332.         Xf=(float)(Ri-Ti-1)*x[Fi] + (float)Ti*x[Fi+1];                                                           \
  333.         Yf=(float)(Ri-Ti-1)*y[Fi] + (float)Ti*y[Fi+1];                                                           \
  334.         Xa=Xf+0.001; Yb=Yf+0.001;                                                                                \
  335.     Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);                                                         \
  336.     Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);                                                                        \
  337.     Factor2=1-((Xf2+sqr(Yb))*AmpVr2);                                                                        \
  338.         VertX=Factor*Xf;        VertY=Factor*Yf;        VertZ=Factor*Zf;                                         \
  339.         NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ;                                  \
  340.         NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ;                                  \
  341.         glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ));                                           \
  342.     glVertex3f(VertX, VertY, VertZ);                                                                         \
  343.                                                                                                                  \
  344.       }                                                                                                          \
  345.       Xf=(float)Ri*x[Fi+1];                                                                                      \
  346.       Yf=(float)Ri*y[Fi+1];                                                                                      \
  347.       Xa=Xf+0.001; Yb=Yf+0.001;                                                                                  \
  348.       Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);                                                           \
  349.       Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);                                                                          \
  350.       Factor2=1-((Xf2+sqr(Yb))*AmpVr2);                                                                          \
  351.       VertX=Factor*Xf;        VertY=Factor*Yf;        VertZ=Factor*Zf;                                           \
  352.       NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ;                                    \
  353.       NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ;                                    \
  354.       glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ));                                             \
  355.       glVertex3f(VertX, VertY, VertZ);                                                                           \
  356.       glEnd();                                                                                                   \
  357.     }                                                                                                            \
  358.   }                                                                                                              \
  359. }
  360.  
  361. static void draw_tetra( void )
  362. {
  363.   GLuint list;
  364.  
  365.   list = glGenLists( 1 );
  366.   glNewList( list, GL_COMPILE );
  367.   TRIANGLE(2,seno,edgedivisions,0.5/SQRT6);
  368.   glEndList();
  369.  
  370.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
  371.   glCallList(list);
  372.   glPushMatrix();
  373.   glRotatef(180,0,0,1);
  374.   glRotatef(-tetraangle,1,0,0);
  375.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
  376.   glCallList(list);
  377.   glPopMatrix();
  378.   glPushMatrix();
  379.   glRotatef(180,0,1,0);
  380.   glRotatef(-180+tetraangle,0.5,SQRT3/2,0);
  381.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
  382.   glCallList(list);
  383.   glPopMatrix();
  384.   glRotatef(180,0,1,0);
  385.   glRotatef(-180+tetraangle,0.5,-SQRT3/2,0);
  386.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
  387.   glCallList(list);
  388.  
  389.   glDeleteLists(list,1);
  390. }
  391.  
  392. static void draw_cube( void )
  393. {
  394.   GLuint list;
  395.  
  396.   list = glGenLists( 1 );
  397.   glNewList( list, GL_COMPILE );
  398.   SQUARE(2, seno, edgedivisions, 0.5)
  399.   glEndList();
  400.  
  401.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
  402.   glCallList(list);
  403.   glRotatef(cubeangle,1,0,0);
  404.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
  405.   glCallList(list);
  406.   glRotatef(cubeangle,1,0,0);
  407.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
  408.   glCallList(list);
  409.   glRotatef(cubeangle,1,0,0);
  410.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
  411.   glCallList(list);
  412.   glRotatef(cubeangle,0,1,0);
  413.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
  414.   glCallList(list);
  415.   glRotatef(2*cubeangle,0,1,0);
  416.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
  417.   glCallList(list);
  418.  
  419.   glDeleteLists(list,1);
  420. }
  421.  
  422. static void draw_octa( void )
  423. {
  424.   GLuint list;
  425.  
  426.   list = glGenLists( 1 );
  427.   glNewList( list, GL_COMPILE );
  428.   TRIANGLE(2,seno,edgedivisions,1/SQRT6);
  429.   glEndList();
  430.  
  431.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
  432.   glCallList(list);
  433.   glPushMatrix();
  434.   glRotatef(180,0,0,1);
  435.   glRotatef(-180+octaangle,1,0,0);
  436.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
  437.   glCallList(list);
  438.   glPopMatrix();
  439.   glPushMatrix();
  440.   glRotatef(180,0,1,0);
  441.   glRotatef(-octaangle,0.5,SQRT3/2,0);
  442.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
  443.   glCallList(list);
  444.   glPopMatrix();
  445.   glPushMatrix();
  446.   glRotatef(180,0,1,0);
  447.   glRotatef(-octaangle,0.5,-SQRT3/2,0);
  448.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
  449.   glCallList(list);
  450.   glPopMatrix();
  451.   glRotatef(180,1,0,0);
  452.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
  453.   glCallList(list);
  454.   glPushMatrix();
  455.   glRotatef(180,0,0,1);
  456.   glRotatef(-180+octaangle,1,0,0);
  457.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
  458.   glCallList(list);
  459.   glPopMatrix();
  460.   glPushMatrix();
  461.   glRotatef(180,0,1,0);
  462.   glRotatef(-octaangle,0.5,SQRT3/2,0);
  463.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]);
  464.   glCallList(list);
  465.   glPopMatrix();
  466.   glRotatef(180,0,1,0);
  467.   glRotatef(-octaangle,0.5,-SQRT3/2,0);
  468.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]);
  469.   glCallList(list);
  470.  
  471.   glDeleteLists(list,1);
  472. }
  473.  
  474. static void draw_dodeca( void )
  475. {
  476.   GLuint list;
  477.  
  478.   #define TAU ((SQRT5+1)/2)
  479.  
  480.   list = glGenLists( 1 );
  481.   glNewList( list, GL_COMPILE );
  482.   PENTAGON(1,seno,edgedivisions,sqr(TAU) * sqrt((TAU+2)/5) / 2);
  483.   glEndList();
  484.  
  485.   glPushMatrix();
  486.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
  487.   glCallList(list);
  488.   glRotatef(180,0,0,1);
  489.   glPushMatrix();
  490.   glRotatef(-dodecaangle,1,0,0);
  491.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
  492.   glCallList(list);
  493.   glPopMatrix();
  494.   glPushMatrix();
  495.   glRotatef(-dodecaangle,cos72,sin72,0);
  496.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
  497.   glCallList(list);
  498.   glPopMatrix();
  499.   glPushMatrix();
  500.   glRotatef(-dodecaangle,cos72,-sin72,0);
  501.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
  502.   glCallList(list);
  503.   glPopMatrix();
  504.   glPushMatrix();
  505.   glRotatef(dodecaangle,cos36,-sin36,0);
  506.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
  507.   glCallList(list);
  508.   glPopMatrix();
  509.   glRotatef(dodecaangle,cos36,sin36,0);
  510.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
  511.   glCallList(list);
  512.   glPopMatrix();
  513.   glRotatef(180,1,0,0);
  514.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]);
  515.   glCallList(list);
  516.   glRotatef(180,0,0,1);
  517.   glPushMatrix();
  518.   glRotatef(-dodecaangle,1,0,0);
  519.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]);
  520.   glCallList(list);
  521.   glPopMatrix();
  522.   glPushMatrix();
  523.   glRotatef(-dodecaangle,cos72,sin72,0);
  524.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]);
  525.   glCallList(list);
  526.   glPopMatrix();
  527.   glPushMatrix();
  528.   glRotatef(-dodecaangle,cos72,-sin72,0);
  529.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]);
  530.   glCallList(list);
  531.   glPopMatrix();
  532.   glPushMatrix();
  533.   glRotatef(dodecaangle,cos36,-sin36,0);
  534.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]);
  535.   glCallList(list);
  536.   glPopMatrix();
  537.   glRotatef(dodecaangle,cos36,sin36,0);
  538.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]);
  539.   glCallList(list);
  540.  
  541.   glDeleteLists(list,1);
  542. }
  543.  
  544. static void draw_ico( void )
  545. {
  546.   GLuint list;
  547.  
  548.   list = glGenLists( 1 );
  549.   glNewList( list, GL_COMPILE );
  550.   TRIANGLE(1.5,seno,edgedivisions,(3*SQRT3+SQRT15)/12);
  551.   glEndList();
  552.  
  553.   glPushMatrix();
  554.  
  555.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
  556.   glCallList(list);
  557.   glPushMatrix();
  558.   glRotatef(180,0,0,1);
  559.   glRotatef(-icoangle,1,0,0);
  560.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
  561.   glCallList(list);
  562.   glPushMatrix();
  563.   glRotatef(180,0,1,0);
  564.   glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  565.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
  566.   glCallList(list);
  567.   glPopMatrix();
  568.   glRotatef(180,0,1,0);
  569.   glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  570.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
  571.   glCallList(list);
  572.   glPopMatrix();
  573.   glPushMatrix();
  574.   glRotatef(180,0,1,0);
  575.   glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  576.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
  577.   glCallList(list);
  578.   glPushMatrix();
  579.   glRotatef(180,0,1,0);
  580.   glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  581.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
  582.   glCallList(list);
  583.   glPopMatrix();
  584.   glRotatef(180,0,0,1);
  585.   glRotatef(-icoangle,1,0,0);
  586.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]);
  587.   glCallList(list);
  588.   glPopMatrix();
  589.   glRotatef(180,0,1,0);
  590.   glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  591.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]);
  592.   glCallList(list);
  593.   glPushMatrix();
  594.   glRotatef(180,0,1,0);
  595.   glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  596.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]);
  597.   glCallList(list);
  598.   glPopMatrix();
  599.   glRotatef(180,0,0,1);
  600.   glRotatef(-icoangle,1,0,0);
  601.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]);
  602.   glCallList(list);
  603.   glPopMatrix();
  604.   glRotatef(180,1,0,0);
  605.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]);
  606.   glCallList(list);
  607.   glPushMatrix();
  608.   glRotatef(180,0,0,1);
  609.   glRotatef(-icoangle,1,0,0);
  610.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]);
  611.   glCallList(list);
  612.   glPushMatrix();
  613.   glRotatef(180,0,1,0);
  614.   glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  615.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[12]);
  616.   glCallList(list);
  617.   glPopMatrix();
  618.   glRotatef(180,0,1,0);
  619.   glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  620.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[13]);
  621.   glCallList(list);
  622.   glPopMatrix();
  623.   glPushMatrix();
  624.   glRotatef(180,0,1,0);
  625.   glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  626.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[14]);
  627.   glCallList(list);
  628.   glPushMatrix();
  629.   glRotatef(180,0,1,0);
  630.   glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  631.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[15]);
  632.   glCallList(list);
  633.   glPopMatrix();
  634.   glRotatef(180,0,0,1);
  635.   glRotatef(-icoangle,1,0,0);
  636.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[16]);
  637.   glCallList(list);
  638.   glPopMatrix();
  639.   glRotatef(180,0,1,0);
  640.   glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  641.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[17]);
  642.   glCallList(list);
  643.   glPushMatrix();
  644.   glRotatef(180,0,1,0);
  645.   glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  646.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[18]);
  647.   glCallList(list);
  648.   glPopMatrix();
  649.   glRotatef(180,0,0,1);
  650.   glRotatef(-icoangle,1,0,0);
  651.   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[19]);
  652.   glCallList(list);
  653.  
  654.   glDeleteLists(list,1);
  655. }
  656.  
  657. static void draw ( void ) {
  658.   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  659.  
  660.   glPushMatrix();
  661.  
  662.     glTranslatef( 0.0, 0.0, -10.0 );
  663.     glScalef( Scale*WindH/WindW, Scale, Scale );
  664.     glTranslatef(2.5*WindW/WindH*sin(step*1.11),2.5*cos(step*1.25*1.11),0);
  665.     glRotatef(step*100,1,0,0);
  666.     glRotatef(step*95,0,1,0);
  667.     glRotatef(step*90,0,0,1);
  668.  
  669.   seno=(sin(step)+1.0/3.0)*(4.0/5.0)*Magnitude;
  670.  
  671.   draw_object();
  672.  
  673.   glPopMatrix();
  674.  
  675.   glFlush();
  676.  
  677.   tkSwapBuffers();
  678.  
  679.   step+=0.05;
  680. }
  681.  
  682. static void idle_( void )
  683. {
  684.   draw();
  685. }
  686.  
  687. static void reshape( int width, int height )
  688. {
  689.   glViewport(0, 0, WindW=(GLint)width, WindH=(GLint)height);
  690.   glMatrixMode(GL_PROJECTION);
  691.   glLoadIdentity();
  692.   glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
  693.   glMatrixMode(GL_MODELVIEW);
  694. }
  695.  
  696. static void pinit(void);
  697.  
  698. static GLenum key(int k, GLenum mask)
  699. {
  700.   switch (k) {
  701.     case TK_1: object=1; break;
  702.     case TK_2: object=2; break;
  703.     case TK_3: object=3; break;
  704.     case TK_4: object=4; break;
  705.     case TK_5: object=5; break;
  706.     case TK_SPACE: mono^=1; break;
  707.     case TK_RETURN: smooth^=1; break;
  708.     case TK_ESCAPE:
  709.       tkQuit();
  710.   }
  711.   pinit();
  712.   return GL_FALSE;
  713. }
  714.  
  715. static void pinit(void)
  716. {
  717.   switch(object) {
  718.     case 1:
  719.       draw_object=draw_tetra;
  720.       MaterialColor[0]=MaterialRed;
  721.       MaterialColor[1]=MaterialGreen;
  722.       MaterialColor[2]=MaterialBlue;
  723.       MaterialColor[3]=MaterialWhite;
  724.       edgedivisions=tetradivisions;
  725.       Magnitude=2.5;
  726.       break;
  727.     case 2:
  728.       draw_object=draw_cube;
  729.       MaterialColor[0]=MaterialRed;
  730.       MaterialColor[1]=MaterialGreen;
  731.       MaterialColor[2]=MaterialCyan;
  732.       MaterialColor[3]=MaterialMagenta;
  733.       MaterialColor[4]=MaterialYellow;
  734.       MaterialColor[5]=MaterialBlue;
  735.       edgedivisions=cubedivisions;
  736.       Magnitude=2.0;
  737.       break;
  738.     case 3:
  739.       draw_object=draw_octa;
  740.       MaterialColor[0]=MaterialRed;
  741.       MaterialColor[1]=MaterialGreen;
  742.       MaterialColor[2]=MaterialBlue;
  743.       MaterialColor[3]=MaterialWhite;
  744.       MaterialColor[4]=MaterialCyan;
  745.       MaterialColor[5]=MaterialMagenta;
  746.       MaterialColor[6]=MaterialGray;
  747.       MaterialColor[7]=MaterialYellow;
  748.       edgedivisions=octadivisions;
  749.       Magnitude=2.5;
  750.       break;
  751.     case 4:
  752.       draw_object=draw_dodeca;
  753.       MaterialColor[ 0]=MaterialRed;
  754.       MaterialColor[ 1]=MaterialGreen;
  755.       MaterialColor[ 2]=MaterialCyan;
  756.       MaterialColor[ 3]=MaterialBlue;
  757.       MaterialColor[ 4]=MaterialMagenta;
  758.       MaterialColor[ 5]=MaterialYellow;
  759.       MaterialColor[ 6]=MaterialGreen;
  760.       MaterialColor[ 7]=MaterialCyan;
  761.       MaterialColor[ 8]=MaterialRed;
  762.       MaterialColor[ 9]=MaterialMagenta;
  763.       MaterialColor[10]=MaterialBlue;
  764.       MaterialColor[11]=MaterialYellow;
  765.       edgedivisions=dodecadivisions;
  766.       Magnitude=2.0;
  767.       break;
  768.     case 5:
  769.       draw_object=draw_ico;
  770.       MaterialColor[ 0]=MaterialRed;
  771.       MaterialColor[ 1]=MaterialGreen;
  772.       MaterialColor[ 2]=MaterialBlue;
  773.       MaterialColor[ 3]=MaterialCyan;
  774.       MaterialColor[ 4]=MaterialYellow;
  775.       MaterialColor[ 5]=MaterialMagenta;
  776.       MaterialColor[ 6]=MaterialRed;
  777.       MaterialColor[ 7]=MaterialGreen;
  778.       MaterialColor[ 8]=MaterialBlue;
  779.       MaterialColor[ 9]=MaterialWhite;
  780.       MaterialColor[10]=MaterialCyan;
  781.       MaterialColor[11]=MaterialYellow;
  782.       MaterialColor[12]=MaterialMagenta;
  783.       MaterialColor[13]=MaterialRed;
  784.       MaterialColor[14]=MaterialGreen;
  785.       MaterialColor[15]=MaterialBlue;
  786.       MaterialColor[16]=MaterialCyan;
  787.       MaterialColor[17]=MaterialYellow;
  788.       MaterialColor[18]=MaterialMagenta;
  789.       MaterialColor[19]=MaterialGray;
  790.       edgedivisions=icodivisions;
  791.       Magnitude=2.5;
  792.       break;
  793.   }
  794.   if (mono) {
  795.     int loop;
  796.     for (loop=0; loop<20; loop++) MaterialColor[loop]=MaterialGray;
  797.   }
  798.   if (smooth) {
  799.     glShadeModel( GL_SMOOTH );
  800.   } else {
  801.     glShadeModel( GL_FLAT );
  802.   }
  803.  
  804. }
  805.  
  806. void INIT(void)
  807. {
  808.   printf("Morph 3D - Shows morphing platonic polyhedra\n");
  809.   printf("Author: Marcelo Fernandes Vianna (vianna@cat.cbpf.br)\n\n");
  810.   printf("  [1]    - Tetrahedron\n");
  811.   printf("  [2]    - Hexahedron (Cube)\n");
  812.   printf("  [3]    - Octahedron\n");
  813.   printf("  [4]    - Dodecahedron\n");
  814.   printf("  [5]    - Icosahedron\n");
  815.   printf("[SPACE]  - Toggle colored faces\n");
  816.   printf("[RETURN] - Toggle smooth/flat shading\n");
  817.   printf(" [ESC]   - Quit\n");
  818.  
  819.   object=1;
  820.  
  821.   tkInitPosition(0,0,640,480);
  822.  
  823.   tkInitDisplayMode( TK_DOUBLE | TK_DIRECT | TK_RGB );
  824.  
  825.   if (tkInitWindow("Morph 3D - Shows morphing platonic polyhedra") == GL_FALSE) {
  826.     tkQuit();
  827.   }
  828.  
  829.   glClearDepth(1.0);
  830.   glClearColor( 0.0, 0.0, 0.0, 1.0 );
  831.   glColor3f( 1.0, 1.0, 1.0 );
  832.  
  833.   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  834.   glFlush();
  835.   tkSwapBuffers();
  836.  
  837.   glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  838.   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  839.   glLightfv(GL_LIGHT0, GL_POSITION, position0);
  840.   glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
  841.   glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
  842.   glLightfv(GL_LIGHT1, GL_POSITION, position1);
  843.   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  844.   glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
  845.   glEnable(GL_LIGHTING);
  846.   glEnable(GL_LIGHT0);
  847.   glEnable(GL_LIGHT1);
  848.   glEnable(GL_DEPTH_TEST);
  849.   glEnable(GL_NORMALIZE);
  850.  
  851.   glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
  852.   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
  853.  
  854.   glHint(GL_FOG_HINT, GL_FASTEST);
  855.   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
  856.   glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
  857.  
  858.   pinit();
  859.  
  860.   tkExposeFunc( reshape );
  861.   tkReshapeFunc( reshape );
  862.   tkKeyDownFunc( key );
  863.   tkIdleFunc( idle_ );
  864.   tkDisplayFunc( draw );
  865.   tkExec();
  866.   
  867. }
  868.  
  869. int main(int argc, char **argv)
  870. {
  871.   INIT();
  872.   return(0);
  873. }
  874.